<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>灯泡</title>
    <style>
        .box{
            width: 50px;
            height: 50px;
            background-color: red;
        }
        .box1{
            width: 200px;
            height: 200px;
           background-color: darkmagenta;
        }
        .id{
            width: 100%;
            height: 100%;
            border-radius: 10ex;
            outline: none;
            background-color: red;
        }
        
    </style>
</head>
<body>
    <!-- <div class="box">
       
    </div> -->
    <div class="box1"> </div>
    <img src="Light.png" alt="">
<script>
    var box=document.querySelector('.box');
    var box1=document.querySelector('.box1');
    var id=document.querySelector('.id');
    
    let flag = false;
        box1.onclick=function(){
        if(flag === true){
            box1.style.background='darkmagenta'; 
            flag = false
        }else{
            box1.style.background='red';  
            flag = true
         }
     }
    let img = document.querySelector('img');
    console.log(img)
    img.onclick=function(){
        if(img.getAttribute('src')=='./Light bulb.png'){
            img.setAttribute('src','./Light.png')
        }else{
            img.setAttribute('src','./Light bulb.png')
        }
    }
</script>
</body>
</html>